# -*- coding: utf-8 -*-
import time

from paddleocr import PaddleOCR

from submodules.common.lib.log_ import logger
logger =get_logger()


def ocr(img_path):
    t1 = time.time()
    res = []
    ocr = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=False)
    res2 = ocr.ocr(img_path, cls=True)
    for item in res2:
        x1 = item[0][0][0]
        y1 = item[0][0][1]
        x2 = item[0][2][0]
        y2 = item[0][2][1]
        ocr_text = item[1][0].replace(" ", "")
        ocr_prob = item[1][1]
        res.append([(x1, y1, x2, y2), ocr_text, ocr_prob])
    t2 = time.time()
    logger.info(f"ocr_time:{t2 - t1}")
    return res


if __name__ == "__main__":
    def test_ocr():
        img_path = "test_data/test.png"
        res = ocr(img_path)
        print(res)



    test_ocr()
